import { CHANGE_INPUT, ADD_ITEM, DEL_ITEM, GET_LIST } from './actionTypes'

const defaultState = {
    inputValue:"请输入内容",
    list:[
        '测试，第一条记录',
        '测试，第二条记录',
        '测试，第三条记录',
    ]
}

export default (state = defaultState, action) => {
    console.log(state, action)
    const newState = JSON.parse(JSON.stringify(state))

    //state值只能传递，不能使用
    if (action.type == CHANGE_INPUT) {
        newState.inputValue = action.value
        return newState
    }

    if (action.type == ADD_ITEM) {
        newState.list.push(newState.inputValue)
        return newState
    }

    if (action.type == DEL_ITEM) {
        newState.list.splice(action.index,1)
        return newState
    }

    if(action.type === GET_LIST ){ //根据type值，编写业务逻辑
        newState.list = action.data //复制性的List数组进去
        return newState
    }

    return state
}